<template>
    <div class="addProd">
        <div class="box flex-b">
            <div class="left">
                <div class="prod-title">
                    <div class="flex-a">
                        <div class="basic">基本信息</div>
                    </div>
                </div>
                <div class="prod-content" style="padding-left: 10px;">
                    <el-form ref="form" :model="form" class="input">
                        <div>
                            <p>店铺logo</p>
                            <el-upload class="avatar-uploader" :action="action" :headers="headers"
                                :show-file-list="false" :on-success="handleAvatarSuccess">
                                <img v-if="form.storeLogo" :src="form.storeLogo" class="avatar">
                                <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                            </el-upload>
                        </div>
                        <div>
                            <p>店铺图片</p>
                            <el-upload class="avatar-uploader" :action="action" :headers="headers"
                                :show-file-list="false" :on-success="handlePicSuccess">
                                <img v-if="form.storePic" :src="form.storePic" class="avatar">
                                <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                            </el-upload>
                        </div>
                        <div>
                            <p>店铺名称</p>
                            <el-input v-model="form.storeName" placeholder="请输入店铺名称" clearable></el-input>
                        </div>
                        <div>
                            <p>联系电话</p>
                            <el-input v-model="form.storeLepPhone" placeholder="请输入联系电话" clearable></el-input>
                        </div>
                        <div>
                            <p>所在地区</p>
                            <el-cascader v-model="form.place" :options="province" clearable :props="option"></el-cascader>
                        </div>
                        <div>
                            <p>详细地址</p>
                            <el-input v-model="form.initPlace" placeholder="请输入详细地址" clearable></el-input>
                        </div>
                        <div>
                            <p>店铺简介</p>
                            <el-input v-model="form.storeSummary" type="textarea" placeholder="请输入店铺简介" clearable></el-input>
                        </div>
                    </el-form>
                </div>
                <div style="margin-top: 30px;">
                    <el-button type="warning" style="padding:12px 70px" class="btn" @click="submit">提交</el-button>
                    <el-button type="warning" style="padding:12px 50px" class="btn-plain" @click="back">返回上一页</el-button>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
import { addEbbasic, updateEbbasic, getEbbasic, getCity } from "@/api/pet/ebbasic";
import { getToken } from "@/utils/auth";
export default {
    name: "addProd",
    components: {

    },
    data() {
        return {
            form: {
                storeLogo:'',
                storePic:''
            },
            action: process.env.VUE_APP_BASE_API + '/pet/upload/comFile',
            headers: {
                Authorization: "Bearer " + getToken(),
            },
            rules: {},
            loading: false,
            id: '',
            province: [],
            option: {
                value: 'name',
                label: 'name',
                children: 'child'
            },
        };
    },
    created() {
        if (this.$route.query.id) {
            this.id = this.$route.query.id
            this.getSerDetail(this.$route.query.id)
        }
        this.getCity()//获取省市
    },
    mounted() {

    },
    methods: {
        //获取省市
        getCity() {
            getCity().then(res => {
                if (res.code == 200) {
                    this.province = res.data
                }
            })
        },
        //获取详情
        getSerDetail(id) {
            getEbbasic(id).then(response => {
                this.form = response.data;
                this.form.place = response.data.place.split('-')
            });
        },
        //logo上传成功
        handleAvatarSuccess(res, file) {
            this.form.storeLogo = res.url
        },
        //图片上传成功
        handlePicSuccess(res, file) {
            this.form.storePic = res.url
        },
        //提交
        submit() {
            if (this.form.id != null) {
                this.form.place = this.form.place.join('-')
                updateEbbasic(this.form).then(response => {
                    this.$modal.msgSuccess("修改成功");
                    this.$router.push({ path: '/store/ebbasic' })
                });
            } else {
                this.form.place = this.form.place.join('-')
                addEbbasic(this.form).then(response => {
                    this.$modal.msgSuccess("新增成功");
                    this.$router.push({ path: '/store/ebbasic' })
                });
            }
        },
        // 返回上一页
        back() {
            this.$router.push({ path: '/store/ebbasic' })
        },
    }
};
</script>
<style scoped lang="scss">
.box {
    position: relative;

    .left {
        width: 100%;
    }

    .prod-title {
        .basic {
            font-size: 18px;
            color: #333336;
            font-weight: 700;
            margin-right: 30px;

            span {
                color: #409eff;
                font-size: 12px;
                font-weight: normal;
                margin: 0 20px 0 5px;
            }
        }
    }

    .prod-content {
        margin-top: 20px;

        div {
            margin-bottom: 15px;

            .mr {
                margin-right: 10px;
            }

            p {
                color: #000000;
                font-size: 14px;

                span {
                    color: #b3b3b3;
                    font-size: 12px;
                }
            }

            .el-input {
                width: 240px;
            }

            .select {
                margin-left: 10px;
                width: 80px;
            }

            .el-textarea {
                width: 500px;
            }

            .el-button.btn {
                margin-left: 10px;
            }

            .tip {
                display: inline-block;
                font-size: 12px;
                color: #333336;
                margin-left: 5px;

                span {
                    color: #409eff;
                }

                span:hover {
                    cursor: pointer;
                }
            }

        }

        .flex {
            p {
                margin-top: 0 !important;
            }
        }

        .suggest {
            span {
                color: rgb(245, 108, 108);
                font-size: 12px;
            }
        }

        .table {
            margin-left: 130px;

            .el-input {
                width: 120px !important;
            }

            .el-textarea {
                width: 150px !important;
            }

            div {
                color: #409eff;
            }

            .switch {
                div {
                    margin: 0;
                }

                span {
                    display: inline-block;
                    font-size: 14px;
                    color: #606266;
                    width: 110px;
                    text-align: left;
                    box-sizing: border-box;
                }
            }
        }
    }
}

.submit-foot {
    position: fixed;
    bottom: 20px;
    background-color: #fff;
    width: 100%;
    height: 60px;
    z-index: 77;
    padding-left: 20px;
    margin-left: -18px;
    border-top: 1px solid rgba(0, 0, 0, .12);
    box-shadow: 6px 0 6px rgba(0, 0, 0, .12);
    line-height: 60px;
    margin-bottom: -20px;

}
</style>
